##### ####################################################### ######
#####                                                         ######
#####   Input: raw Prolific pre-testing data                  ######
#####   Output: cleaned up data with only relevant variables  ######
#####                                                         ######
##### ####################################################### ######

setwd("/Users/lotte/Dropbox/PhD/style_experiment/replication")
rm(list=ls())

# Load libraries

library(data.table) # CRAN v1.14.2
library(plyr) # CRAN v1.8.6
library(dplyr) # CRAN v1.0.9
library(tidyverse) # CRAN v1.3.1
library(ggplot2) # CRAN v3.3.6

# Load raw pre-testing data

pretest <- read.csv("data/pretesting_raw.csv", stringsAsFactors = FALSE,
                    header=TRUE, na.strings=c("", "NA"))

# Sort order of variables

pretest$emotion_control_housing <- factor(NA, levels = c("Strongly disagree", "Disagree", "Neither agree nor disagree",
                                                         "Agree", "Strongly agree"))
pretest$emotion_control_housing[pretest$emo_control_housing=="Strongly disagree"] <- "Strongly disagree"
pretest$emotion_control_housing[pretest$emo_control_housing=="Disagree"] <- "Disagree"
pretest$emotion_control_housing[pretest$emo_control_housing=="Neither agree nor disagree"] <- "Neither agree nor disagree"
pretest$emotion_control_housing[pretest$emo_control_housing=="Agree"] <- "Agree"
pretest$emotion_control_housing[pretest$emo_control_housing=="Strongly agree"] <- "Strongly agree"
table(pretest$emotion_control_housing)

pretest$emotion_treatment_housing <- factor(NA, levels = c("Strongly disagree", "Disagree", "Neither agree nor disagree",
                                                         "Agree", "Strongly agree"))
pretest$emotion_treatment_housing[pretest$emo_treatment_housin=="Strongly disagree"] <- "Strongly disagree"
pretest$emotion_treatment_housing[pretest$emo_treatment_housin=="Disagree"] <- "Disagree"
pretest$emotion_treatment_housing[pretest$emo_treatment_housin=="Neither agree nor disagree"] <- "Neither agree nor disagree"
pretest$emotion_treatment_housing[pretest$emo_treatment_housin=="Agree"] <- "Agree"
pretest$emotion_treatment_housing[pretest$emo_treatment_housin=="Strongly agree"] <- "Strongly agree"
table(pretest$emotion_treatment_housing)

pretest$emotion_control_transport <- factor(NA, levels = c("Strongly disagree", "Disagree", "Neither agree nor disagree",
                                                           "Agree", "Strongly agree"))
pretest$emotion_control_transport[pretest$emo_control_trans=="Strongly disagree"] <- "Strongly disagree"
pretest$emotion_control_transport[pretest$emo_control_trans=="Disagree"] <- "Disagree"
pretest$emotion_control_transport[pretest$emo_control_trans=="Neither agree nor disagree"] <- "Neither agree nor disagree"
pretest$emotion_control_transport[pretest$emo_control_trans=="Agree"] <- "Agree"
pretest$emotion_control_transport[pretest$emo_control_trans=="Strongly agree"] <- "Strongly agree"
table(pretest$emotion_control_transport)

pretest$emotion_treatment_transport <- factor(NA, levels = c("Strongly disagree", "Disagree", "Neither agree nor disagree",
                                                           "Agree", "Strongly agree"))
pretest$emotion_treatment_transport[pretest$emo_treatment_transp=="Strongly disagree"] <- "Strongly disagree"
pretest$emotion_treatment_transport[pretest$emo_treatment_transp=="Disagree"] <- "Disagree"
pretest$emotion_treatment_transport[pretest$emo_treatment_transp=="Neither agree nor disagree"] <- "Neither agree nor disagree"
pretest$emotion_treatment_transport[pretest$emo_treatment_transp=="Agree"] <- "Agree"
pretest$emotion_treatment_transport[pretest$emo_treatment_transp=="Strongly agree"] <- "Strongly agree"
table(pretest$emotion_treatment_transport)

pretest$emotion_control_health <- factor(NA, levels = c("Strongly disagree", "Disagree", "Neither agree nor disagree",
                                                             "Agree", "Strongly agree"))
pretest$emotion_control_health[pretest$emo_control_health=="Strongly disagree"] <- "Strongly disagree"
pretest$emotion_control_health[pretest$emo_control_health=="Disagree"] <- "Disagree"
pretest$emotion_control_health[pretest$emo_control_health=="Neither agree nor disagree"] <- "Neither agree nor disagree"
pretest$emotion_control_health[pretest$emo_control_health=="Agree"] <- "Agree"
pretest$emotion_control_health[pretest$emo_control_health=="Strongly agree"] <- "Strongly agree"
table(pretest$emotion_control_health)

pretest$emotion_treatment_health <- factor(NA, levels = c("Strongly disagree", "Disagree", "Neither agree nor disagree",
                                                        "Agree", "Strongly agree"))
pretest$emotion_treatment_health[pretest$emo_treatment_health=="Strongly disagree"] <- "Strongly disagree"
pretest$emotion_treatment_health[pretest$emo_treatment_health=="Disagree"] <- "Disagree"
pretest$emotion_treatment_health[pretest$emo_treatment_health=="Neither agree nor disagree"] <- "Neither agree nor disagree"
pretest$emotion_treatment_health[pretest$emo_treatment_health=="Agree"] <- "Agree"
pretest$emotion_treatment_health[pretest$emo_treatment_health=="Strongly agree"] <- "Strongly agree"
table(pretest$emotion_treatment_health)

pretest$evidence_statistics_health <- factor(NA, levels = c("Strongly disagree", "Disagree", "Neither agree nor disagree",
                                                          "Agree", "Strongly agree"))
pretest$evidence_statistics_health[pretest$evid_stats_health=="Strongly disagree"] <- "Strongly disagree"
pretest$evidence_statistics_health[pretest$evid_stats_health=="Disagree"] <- "Disagree"
pretest$evidence_statistics_health[pretest$evid_stats_health=="Neither agree nor disagree"] <- "Neither agree nor disagree"
pretest$evidence_statistics_health[pretest$evid_stats_health=="Agree"] <- "Agree"
pretest$evidence_statistics_health[pretest$evid_stats_health=="Strongly agree"] <- "Strongly agree"
table(pretest$evidence_statistics_health)

pretest$evidence_anecdote_health <- factor(NA, levels = c("Strongly disagree", "Disagree", "Neither agree nor disagree",
                                                            "Agree", "Strongly agree"))
pretest$evidence_anecdote_health[pretest$evid_anecdote_health=="Strongly disagree"] <- "Strongly disagree"
pretest$evidence_anecdote_health[pretest$evid_anecdote_health=="Disagree"] <- "Disagree"
pretest$evidence_anecdote_health[pretest$evid_anecdote_health=="Neither agree nor disagree"] <- "Neither agree nor disagree"
pretest$evidence_anecdote_health[pretest$evid_anecdote_health=="Agree"] <- "Agree"
pretest$evidence_anecdote_health[pretest$evid_anecdote_health=="Strongly agree"] <- "Strongly agree"
table(pretest$evidence_anecdote_health)

pretest$evidence_statistics_transport <- factor(NA, levels = c("Strongly disagree", "Disagree", "Neither agree nor disagree",
                                                            "Agree", "Strongly agree"))
pretest$evidence_statistics_transport[pretest$evid_stats_tran=="Strongly disagree"] <- "Strongly disagree"
pretest$evidence_statistics_transport[pretest$evid_stats_tran=="Disagree"] <- "Disagree"
pretest$evidence_statistics_transport[pretest$evid_stats_tran=="Neither agree nor disagree"] <- "Neither agree nor disagree"
pretest$evidence_statistics_transport[pretest$evid_stats_tran=="Agree"] <- "Agree"
pretest$evidence_statistics_transport[pretest$evid_stats_tran=="Strongly agree"] <- "Strongly agree"
table(pretest$evidence_statistics_transport)

pretest$evidence_anecdote_transport <- factor(NA, levels = c("Strongly disagree", "Disagree", "Neither agree nor disagree",
                                                          "Agree", "Strongly agree"))
pretest$evidence_anecdote_transport[pretest$evid_anecdote_transp=="Strongly disagree"] <- "Strongly disagree"
pretest$evidence_anecdote_transport[pretest$evid_anecdote_transp=="Disagree"] <- "Disagree"
pretest$evidence_anecdote_transport[pretest$evid_anecdote_transp=="Neither agree nor disagree"] <- "Neither agree nor disagree"
pretest$evidence_anecdote_transport[pretest$evid_anecdote_transp=="Agree"] <- "Agree"
pretest$evidence_anecdote_transport[pretest$evid_anecdote_transp=="Strongly agree"] <- "Strongly agree"
table(pretest$evidence_anecdote_transport)

pretest$evidence_statistics_housing <- factor(NA, levels = c("Strongly disagree", "Disagree", "Neither agree nor disagree",
                                                               "Agree", "Strongly agree"))
pretest$evidence_statistics_housing[pretest$evid_statistics_hous=="Strongly disagree"] <- "Strongly disagree"
pretest$evidence_statistics_housing[pretest$evid_statistics_hous=="Disagree"] <- "Disagree"
pretest$evidence_statistics_housing[pretest$evid_statistics_hous=="Neither agree nor disagree"] <- "Neither agree nor disagree"
pretest$evidence_statistics_housing[pretest$evid_statistics_hous=="Agree"] <- "Agree"
pretest$evidence_statistics_housing[pretest$evid_statistics_hous=="Strongly agree"] <- "Strongly agree"
table(pretest$evidence_statistics_housing)

pretest$evidence_anecdote_housing <- factor(NA, levels = c("Strongly disagree", "Disagree", "Neither agree nor disagree",
                                                             "Agree", "Strongly agree"))
pretest$evidence_anecdote_housing[pretest$evid_anecdote_house=="Strongly disagree"] <- "Strongly disagree"
pretest$evidence_anecdote_housing[pretest$evid_anecdote_house=="Disagree"] <- "Disagree"
pretest$evidence_anecdote_housing[pretest$evid_anecdote_house=="Neither agree nor disagree"] <- "Neither agree nor disagree"
pretest$evidence_anecdote_housing[pretest$evid_anecdote_house=="Agree"] <- "Agree"
pretest$evidence_anecdote_housing[pretest$evid_anecdote_house=="Strongly agree"] <- "Strongly agree"
table(pretest$evidence_anecdote_housing)

pretest$aggression_control_housing <- factor(NA, levels = c("Strongly disagree", "Disagree", "Neither agree nor disagree",
                                                           "Agree", "Strongly agree"))
pretest$aggression_control_housing[pretest$agg_control_housing=="Strongly disagree"] <- "Strongly disagree"
pretest$aggression_control_housing[pretest$agg_control_housing=="Disagree"] <- "Disagree"
pretest$aggression_control_housing[pretest$agg_control_housing=="Neither agree nor disagree"] <- "Neither agree nor disagree"
pretest$aggression_control_housing[pretest$agg_control_housing=="Agree"] <- "Agree"
pretest$aggression_control_housing[pretest$agg_control_housing=="Strongly agree"] <- "Strongly agree"
table(pretest$aggression_control_housing)

pretest$aggression_treatment_housing <- factor(NA, levels = c("Strongly disagree", "Disagree", "Neither agree nor disagree",
                                                            "Agree", "Strongly agree"))
pretest$aggression_treatment_housing[pretest$agg_treatment_housin=="Strongly disagree"] <- "Strongly disagree"
pretest$aggression_treatment_housing[pretest$agg_treatment_housin=="Disagree"] <- "Disagree"
pretest$aggression_treatment_housing[pretest$agg_treatment_housin=="Neither agree nor disagree"] <- "Neither agree nor disagree"
pretest$aggression_treatment_housing[pretest$agg_treatment_housin=="Agree"] <- "Agree"
pretest$aggression_treatment_housing[pretest$agg_treatment_housin=="Strongly agree"] <- "Strongly agree"
table(pretest$aggression_treatment_housing)

pretest$aggression_control_health <- factor(NA, levels = c("Strongly disagree", "Disagree", "Neither agree nor disagree",
                                                            "Agree", "Strongly agree"))
pretest$aggression_control_health[pretest$agg_control_health=="Strongly disagree"] <- "Strongly disagree"
pretest$aggression_control_health[pretest$agg_control_health=="Disagree"] <- "Disagree"
pretest$aggression_control_health[pretest$agg_control_health=="Neither agree nor disagree"] <- "Neither agree nor disagree"
pretest$aggression_control_health[pretest$agg_control_health=="Agree"] <- "Agree"
pretest$aggression_control_health[pretest$agg_control_health=="Strongly agree"] <- "Strongly agree"
table(pretest$aggression_control_health)

pretest$aggression_treatment_health <- factor(NA, levels = c("Strongly disagree", "Disagree", "Neither agree nor disagree",
                                                              "Agree", "Strongly agree"))
pretest$aggression_treatment_health[pretest$agg_treatment_health=="Strongly disagree"] <- "Strongly disagree"
pretest$aggression_treatment_health[pretest$agg_treatment_health=="Disagree"] <- "Disagree"
pretest$aggression_treatment_health[pretest$agg_treatment_health=="Neither agree nor disagree"] <- "Neither agree nor disagree"
pretest$aggression_treatment_health[pretest$agg_treatment_health=="Agree"] <- "Agree"
pretest$aggression_treatment_health[pretest$agg_treatment_health=="Strongly agree"] <- "Strongly agree"
table(pretest$aggression_treatment_health)

pretest$aggression_control_transport <- factor(NA, levels = c("Strongly disagree", "Disagree", "Neither agree nor disagree",
                                                           "Agree", "Strongly agree"))
pretest$aggression_control_transport[pretest$agg_control_transp=="Strongly disagree"] <- "Strongly disagree"
pretest$aggression_control_transport[pretest$agg_control_transp=="Disagree"] <- "Disagree"
pretest$aggression_control_transport[pretest$agg_control_transp=="Neither agree nor disagree"] <- "Neither agree nor disagree"
pretest$aggression_control_transport[pretest$agg_control_transp=="Agree"] <- "Agree"
pretest$aggression_control_transport[pretest$agg_control_transp=="Strongly agree"] <- "Strongly agree"
table(pretest$aggression_control_transport)

pretest$aggression_treatment_transport <- factor(NA, levels = c("Strongly disagree", "Disagree", "Neither agree nor disagree",
                                                             "Agree", "Strongly agree"))
pretest$aggression_treatment_transport[pretest$agg_treatment_transp=="Strongly disagree"] <- "Strongly disagree"
pretest$aggression_treatment_transport[pretest$agg_treatment_transp=="Disagree"] <- "Disagree"
pretest$aggression_treatment_transport[pretest$agg_treatment_transp=="Neither agree nor disagree"] <- "Neither agree nor disagree"
pretest$aggression_treatment_transport[pretest$agg_treatment_transp=="Agree"] <- "Agree"
pretest$aggression_treatment_transport[pretest$agg_treatment_transp=="Strongly agree"] <- "Strongly agree"
table(pretest$aggression_treatment_transport)

# Remove unnecessary variables

pretest$StartDate <- NULL
pretest$EndDate <- NULL
pretest$any_other_feedback <- NULL
pretest$IPAddress <- NULL
pretest$Status <- NULL
pretest$Progress <- NULL
pretest$Finished <- NULL
pretest$RecordedDate <- NULL
pretest$RecipientLastName <- NULL
pretest$RecipientFirstName <- NULL
pretest$RecipientEmail <- NULL
pretest$ExternalReference <- NULL
pretest$LocationLatitude <- NULL
pretest$LocationLongitude <- NULL
pretest$consent <- NULL
pretest$DistributionChannel <- NULL
pretest$UserLanguage <- NULL
pretest$emo_control_housing <- NULL
pretest$emo_treatment_housin <- NULL
pretest$emo_control_trans <- NULL
pretest$emo_treatment_transp <- NULL
pretest$emo_control_health <- NULL
pretest$emo_treatment_health <- NULL
pretest$evid_stats_health <- NULL
pretest$evid_anecdote_health <- NULL
pretest$evid_stats_tran <- NULL
pretest$evid_anecdote_transp <- NULL
pretest$evid_statistics_hous <- NULL
pretest$evid_anecdote_house <- NULL
pretest$agg_control_housing <- NULL
pretest$agg_treatment_housin <- NULL
pretest$agg_control_health <- NULL
pretest$agg_treatment_health <- NULL
pretest$agg_control_transp <- NULL
pretest$agg_treatment_transp <- NULL

# Save clean data

pretest_clean <- pretest
save(pretest_clean, file = "data/pretest_clean.Rdata")

# Load clean data

load("data/pretest_clean.Rdata")
pretest <- pretest_clean

# Bar charts

emotion_control_transport <- ggplot(data=subset(pretest, !is.na(emotion_control_transport)), aes(x=emotion_control_transport)) +
  geom_bar(aes(y = (..count..)/sum(..count..)), fill="lightseagreen",  alpha=0.9) +
  theme_bw() +
  theme(axis.text.x=element_text(size = 8, angle=30, hjust=1),
        plot.title = element_text(hjust = 0.5, size = 11),
        axis.text=element_text(size=9),
        axis.title.y=element_text(size=9)) +
  labs(y = "Proportion of responses", title = "Emotion control transport", x = "")

emotion_treatment_transport <- ggplot(data=subset(pretest, !is.na(emotion_treatment_transport)), aes(x=emotion_treatment_transport)) +
  geom_bar(aes(y = (..count..)/sum(..count..)), fill="lightseagreen",  alpha=0.9) +
  theme_bw() +
  theme(axis.text.x=element_text(size = 8, angle=30, hjust=1),
        plot.title = element_text(hjust = 0.5, size = 11),
        axis.text=element_text(size=9),
        axis.title.y=element_text(size=9)) +
  labs(y = "Proportion of responses", title = "Emotion treatment transport", x = "")

emotion_control_housing <- ggplot(data=subset(pretest, !is.na(emotion_control_housing )), aes(x=emotion_control_housing)) +
  geom_bar(aes(y = (..count..)/sum(..count..)), fill="lightseagreen",  alpha=0.9) +
  theme_bw() +
  theme(axis.text.x=element_text(size = 8, angle=30, hjust=1),
        plot.title = element_text(hjust = 0.5, size = 11),
        axis.text=element_text(size=9),
        axis.title.y=element_text(size=9)) +
  labs(y = "Proportion of responses", title = "Emotion control housing", x = "")

emotion_treatment_housing <- ggplot(data=subset(pretest, !is.na(emotion_treatment_housing)), aes(x=emotion_treatment_housing)) +
  geom_bar(aes(y = (..count..)/sum(..count..)), fill="lightseagreen",  alpha=0.9) +
  theme_bw() +
  theme(axis.text.x=element_text(size = 8, angle=30, hjust=1),
        plot.title = element_text(hjust = 0.5, size = 11),
        axis.text=element_text(size=9),
        axis.title.y=element_text(size=9)) +
  labs(y = "Proportion of responses", title = "Emotion treatment housing", x = "")

emotion_control_health <- ggplot(data=subset(pretest, !is.na(emotion_control_health)), aes(x=emotion_control_health)) +
  geom_bar(aes(y = (..count..)/sum(..count..)), fill="lightseagreen",  alpha=0.9) +
  theme_bw() +
  theme(axis.text.x=element_text(size = 8, angle=30, hjust=1),
        plot.title = element_text(hjust = 0.5, size = 11),
        axis.text=element_text(size=9),
        axis.title.y=element_text(size=9)) +
  labs(y = "Proportion of responses", title = "Emotion control health", x = "")

emotion_treatment_health <- ggplot(data=subset(pretest, !is.na(emotion_treatment_health)), aes(x=emotion_treatment_health)) +
  geom_bar(aes(y = (..count..)/sum(..count..)), fill="lightseagreen",  alpha=0.9) +
  theme_bw() +
  theme(axis.text.x=element_text(size = 8, angle=30, hjust=1),
        plot.title = element_text(hjust = 0.5, size = 11),
        axis.text=element_text(size=9),
        axis.title.y=element_text(size=9)) +
  labs(y = "Proportion of responses", title = "Emotion treatment health", x = "")

pdf("analysis/plots/figure_S2_emotion_pretesting.pdf",9,11)
gridExtra::grid.arrange(emotion_control_transport, emotion_treatment_transport, emotion_control_housing, emotion_treatment_housing,
                        emotion_control_health, emotion_treatment_health, ncol=2)
dev.off()

aggression_control_transport <- ggplot(data=subset(pretest, !is.na(aggression_control_transport)), aes(x=aggression_control_transport)) +
  geom_bar(aes(y = (..count..)/sum(..count..)), fill="lightseagreen",  alpha=0.9) +
  theme_bw() +
  theme(axis.text.x=element_text(size = 8, angle=30, hjust=1),
        plot.title = element_text(hjust = 0.5, size = 11),
        axis.text=element_text(size=9),
        axis.title.y=element_text(size=9)) +
  labs(y = "Proportion of responses", title = "Aggression control transport", x = "")

aggression_treatment_transport <- ggplot(data=subset(pretest, !is.na(aggression_treatment_transport)), aes(x=aggression_treatment_transport)) +
  geom_bar(aes(y = (..count..)/sum(..count..)), fill="lightseagreen",  alpha=0.9) +
  theme_bw() +
  theme(axis.text.x=element_text(size = 8, angle=30, hjust=1),
        plot.title = element_text(hjust = 0.5, size = 11),
        axis.text=element_text(size=9),
        axis.title.y=element_text(size=9)) +
  labs(y = "Proportion of responses", title = "Aggression treatment transport", x = "")

aggression_control_housing <- ggplot(data=subset(pretest, !is.na(aggression_control_housing )), aes(x=aggression_control_housing)) +
  geom_bar(aes(y = (..count..)/sum(..count..)), fill="lightseagreen",  alpha=0.9) +
  theme_bw() +
  theme(axis.text.x=element_text(size = 8, angle=30, hjust=1),
        plot.title = element_text(hjust = 0.5, size = 11),
        axis.text=element_text(size=9),
        axis.title.y=element_text(size=9)) +
  labs(y = "Proportion of responses", title = "Aggression control housing", x = "")

aggression_treatment_housing <- ggplot(data=subset(pretest, !is.na(aggression_treatment_housing)), aes(x=aggression_treatment_housing)) +
  geom_bar(aes(y = (..count..)/sum(..count..)), fill="lightseagreen",  alpha=0.9) +
  theme_bw() +
  theme(axis.text.x=element_text(size = 8, angle=30, hjust=1),
        plot.title = element_text(hjust = 0.5, size = 11),
        axis.text=element_text(size=9),
        axis.title.y=element_text(size=9)) +
  labs(y = "Proportion of responses", title = "Aggression treatment housing", x = "")

aggression_control_health <- ggplot(data=subset(pretest, !is.na(aggression_control_health)), aes(x=aggression_control_health)) +
  geom_bar(aes(y = (..count..)/sum(..count..)), fill="lightseagreen",  alpha=0.9) +
  theme_bw() +
  theme(axis.text.x=element_text(size = 8, angle=30, hjust=1),
        plot.title = element_text(hjust = 0.5, size = 11),
        axis.text=element_text(size=9),
        axis.title.y=element_text(size=9)) +
  labs(y = "Proportion of responses", title = "Aggression control health", x = "")

aggression_treatment_health <- ggplot(data=subset(pretest, !is.na(aggression_treatment_health)), aes(x=aggression_treatment_health)) +
  geom_bar(aes(y = (..count..)/sum(..count..)), fill="lightseagreen",  alpha=0.9) +
  theme_bw() +
  theme(axis.text.x=element_text(size = 8, angle=30, hjust=1),
        plot.title = element_text(hjust = 0.5, size = 11),
        axis.text=element_text(size=9),
        axis.title.y=element_text(size=9)) +
  labs(y = "Proportion of responses", title = "Aggression treatment health", x = "")

pdf("analysis/plots/figure_S3_aggression_pretesting.pdf",9,11)
gridExtra::grid.arrange(aggression_control_transport, aggression_treatment_transport, aggression_control_housing, aggression_treatment_housing,
                        aggression_control_health, aggression_treatment_health, ncol=2)
dev.off()


evidence_statistics_transport <- ggplot(data=subset(pretest, !is.na(evidence_statistics_transport)), aes(x=evidence_statistics_transport)) +
  geom_bar(aes(y = (..count..)/sum(..count..)), fill="lightseagreen",  alpha=0.9) +
  theme_bw() +
  theme(axis.text.x=element_text(size = 8, angle=30, hjust=1),
        plot.title = element_text(hjust = 0.5, size = 11),
        axis.text=element_text(size=9),
        axis.title.y=element_text(size=9)) +
  labs(y = "Proportion of responses", title = "Evidence statistics transport", x="")

evidence_anecdote_transport <- ggplot(data=subset(pretest, !is.na(evidence_anecdote_transport)), aes(x=evidence_anecdote_transport)) +
  geom_bar(aes(y = (..count..)/sum(..count..)), fill="lightseagreen",  alpha=0.9) +
  theme_bw() +
  theme(axis.text.x=element_text(size = 8, angle=30, hjust=1),
        plot.title = element_text(hjust = 0.5, size = 11),
        axis.text=element_text(size=9),
        axis.title.y=element_text(size=9)) +
  labs(y = "Proportion of responses", title = "Evidence anecdote transport", x="")

evidence_statistics_housing <- ggplot(data=subset(pretest, !is.na(evidence_statistics_housing)), aes(x=evidence_statistics_housing)) +
  geom_bar(aes(y = (..count..)/sum(..count..)), fill="lightseagreen",  alpha=0.9) +
  theme_bw() +
  theme(axis.text.x=element_text(size = 8, angle=30, hjust=1),
        plot.title = element_text(hjust = 0.5, size = 11),
        axis.text=element_text(size=9),
        axis.title.y=element_text(size=9)) +
  labs(y = "Proportion of responses", title = "Evidence statistics housing", x="")

evidence_anecdote_housing <- ggplot(data=subset(pretest, !is.na(evidence_anecdote_housing )), aes(x=evidence_anecdote_housing)) +
  geom_bar(aes(y = (..count..)/sum(..count..)), fill="lightseagreen",  alpha=0.9) +
  theme_bw() +
  theme(axis.text.x=element_text(size = 8, angle=30, hjust=1),
        plot.title = element_text(hjust = 0.5, size = 11),
        axis.text=element_text(size=9),
        axis.title.y=element_text(size=9)) +
  labs(y = "Proportion of responses", title =  "Evidence anecdote housing", x="")

evidence_statistics_health <- ggplot(data=subset(pretest, !is.na(evidence_statistics_health)), aes(x=evidence_statistics_health)) +
  geom_bar(aes(y = (..count..)/sum(..count..)), fill="lightseagreen",  alpha=0.9) +
  theme_bw() +
  theme(axis.text.x=element_text(size = 8, angle=30, hjust=1),
        plot.title = element_text(hjust = 0.5, size = 11),
        axis.text=element_text(size=9),
        axis.title.y=element_text(size=9)) +
  labs(y = "Proportion of responses", title = "Evidence statistics health", x="")

evidence_anecdote_health <- ggplot(data=subset(pretest, !is.na(evidence_anecdote_health)), aes(x=evidence_anecdote_health)) +
  geom_bar(aes(y = (..count..)/sum(..count..)), fill="lightseagreen",  alpha=0.9) +
  theme_bw() +
  theme(axis.text.x=element_text(size = 8, angle=30, hjust=1),
        plot.title = element_text(hjust = 0.5, size = 11),
        axis.text=element_text(size=9),
        axis.title.y=element_text(size=9)) +
  labs(y = "Proportion of responses", title = "Evidence anecdote health", x="")

pdf("analysis/plots/figure_S4_evidence_pretesting.pdf",9,11)
gridExtra::grid.arrange(evidence_statistics_transport, evidence_anecdote_transport, evidence_statistics_housing, evidence_anecdote_housing,
                        evidence_statistics_health, evidence_anecdote_health, ncol=2)
dev.off()



